package com.cqkjxy.commons.utils;

import java.util.Random;

public final class RandomHelper {

    private static Random random = new Random(System.currentTimeMillis());

    public static int getRandomInt(int max) {
        return random.nextInt(max);
    }

    public static String getRandomString(int length) {
        long randomValue = random.nextLong();
        if (randomValue < 0) {
            randomValue = 0 - randomValue;
        }
        String value = String.valueOf(randomValue);
        if (value.length() <= length)
            return value;

        return value.substring(0, length);
    }

    public static String generateOrderCode(long rewardId, long userId) {
        StringBuilder sb = new StringBuilder();
        sb.append(Long.toHexString(System.currentTimeMillis())).append(rewardId)
                .append(userId).append("-").append(getRandomString(6));
        return sb.toString().toLowerCase();
    }

}
